//
//  SummaryViewController.m
//  AOEProject
//
//  Created by techplus on 9/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SummaryViewController.h"

#import "DetailViewController.h"

@implementation SummaryViewController
@synthesize gameThuButton;
@synthesize theLoaiButton;
@synthesize clanButton;
@synthesize nationButton;
@synthesize backgroundImageView;
@synthesize lowAlphaView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"Tổng hợp";
        self.tabBarItem.image = [UIImage imageNamed:@"Tonghop.png"];
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    //[self.gameThuButton sendSubviewToBack:[self.gameThuButton imageView]];
    [self.gameThuButton setTitleEdgeInsets:UIEdgeInsetsMake(105, -130, 0, 0)];
    [self.theLoaiButton setTitleEdgeInsets:UIEdgeInsetsMake(105, -130, 0, 0)];
    [self.nationButton setTitleEdgeInsets:UIEdgeInsetsMake(105, -130, 0, 0)];
    [self.clanButton setTitleEdgeInsets:UIEdgeInsetsMake(105, -130, 0, 0)];
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Default.png"]];
//    self.backgroundImageView.backgroundColor = background;
//    [background release];
    [backgroundImageView setImage:[UIImage imageNamed:@"Default.png"]];
}

- (void)viewDidUnload
{
    [self setGameThuButton:nil];
    [self setTheLoaiButton:nil];
    [self setClanButton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)viewWillAppear:(BOOL)animated {
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [super viewWillAppear:YES];
    if ([UIDevice currentDevice].orientation!=UIDeviceOrientationLandscapeLeft &&
        [UIDevice currentDevice].orientation!=UIDeviceOrientationLandscapeRight)
    {
        self.backgroundImageView.frame = CGRectMake(0, 0, 320, 480);
        [self.backgroundImageView setImage:[UIImage imageNamed:@"landscape.png"]];
        self.lowAlphaView.frame =   CGRectMake(0, 0, 320, 480);
        self.gameThuButton.frame =  CGRectMake(113, 61, 94, 94);
        self.theLoaiButton.frame =  CGRectMake(13, 159, 94, 94);
        self.nationButton.frame =   CGRectMake(113, 250, 94, 94);
        self.clanButton.frame =     CGRectMake(203, 160, 94, 94);
        [delegate.tabBarController doPortrait];
    }
    else
    {
        self.backgroundImageView.frame = CGRectMake(0, 0, 480, 320);
        [self.backgroundImageView setImage:[UIImage imageNamed:@"Default.png"]];
        self.lowAlphaView.frame =   CGRectMake(0, 0, 480, 320);
        self.gameThuButton.frame =  CGRectMake(20, 75, 94, 94);
        self.theLoaiButton.frame =  CGRectMake(132, 75, 94, 94);
        self.nationButton.frame =   CGRectMake(248, 75, 94, 94);
        self.clanButton.frame =     CGRectMake(366, 75, 94, 94);
        [delegate.tabBarController doLandscape];
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
//    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.backgroundImageView.frame = CGRectMake(0, 0, 480, 320);
        [self.backgroundImageView setImage:[UIImage imageNamed:@"Default.png"]];
        self.lowAlphaView.frame =   CGRectMake(0, 0, 480, 320);
        self.gameThuButton.frame =  CGRectMake(20, 75, 94, 94);
        self.theLoaiButton.frame =  CGRectMake(132, 75, 94, 94);
        self.nationButton.frame =   CGRectMake(248, 75, 94, 94);
        self.clanButton.frame =     CGRectMake(366, 75, 94, 94);
        [delegate.tabBarController doLandscape];
    }
    else
    {
        self.backgroundImageView.frame = CGRectMake(0, 0, 320, 480);
        [self.backgroundImageView setImage:[UIImage imageNamed:@"landscape.png"]];
        self.lowAlphaView.frame =   CGRectMake(0, 0, 320, 480);
        self.gameThuButton.frame =  CGRectMake(113, 61, 94, 94);
        self.theLoaiButton.frame =  CGRectMake(13, 159, 94, 94);
        self.nationButton.frame =   CGRectMake(113, 250, 94, 94);
        self.clanButton.frame =     CGRectMake(203, 160, 94, 94);
        [delegate.tabBarController doPortrait];
    }
}

-(void)loadDetailView:(id)sender{
    
    
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibNameAndType:@"DetailViewController" bundle:nil:(NSInteger *)0:(NSInteger *)0:nil:nil];
    [self.navigationController pushViewController:dvc animated:YES];
    [dvc release];
    
}

-(IBAction)loadTheLoai :(id)sender;
{
    
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibNameAndType:@"DetailViewController" bundle:nil:(NSInteger *)0:(NSInteger *)2:nil:nil];
    [self.navigationController pushViewController:dvc animated:YES];
    [dvc release];
}
-(IBAction)loadClan:(id)sender
{
    
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibNameAndType:@"DetailViewController" bundle:nil:(NSInteger *)0:(NSInteger *)1:nil:nil];
    [self.navigationController pushViewController:dvc animated:YES];
    [dvc release];
}
-(IBAction)loadQuocGia:(id)sender
{
    
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibNameAndType:@"DetailViewController" bundle:nil:(NSInteger *)0:(NSInteger *)3:nil:nil];
    [self.navigationController pushViewController:dvc animated:YES];
    [dvc release];
}

- (void)dealloc {
    [gameThuButton release];
    [theLoaiButton release];
    [clanButton release];
    [super dealloc];
}
@end
